package com.gitee.ly.chain.abstractclass;

import com.gitee.ly.chain.Form;
import com.gitee.ly.chain.Link;

/**
 * AbstractForm
 *
 * @author ly
 **/
public abstract class AbstractForm implements Form {
    private String type;
    private String name;

    public AbstractForm(String type, String name) {
        this.type = type;
        this.name = name;
    }

    @Override
    public final String getType() {
        return type;
    }

    @Override
    public final String getName() {
        return name;
    }

    protected final void excuteInner(String uid, String flowType, String linkType, Object data) {
        Link linK = GlobalTool.getLinK(linkType);
        int linkFormSort = GlobalTool.getLinkFormSort(linkType, this);
        String dataStr = GlobalTool.getJsonSerial(data);
        String format = String.format("开始执行流程[uid:%s,%s,%s]环节[sort:%s,%s,%s]表单[sort:%s,%s,%s]的数据(%s)", uid, flowType, GlobalTool.getFlow(flowType, Object.class).getName(), linK.getSort(), linK.getType(), linK.getName(), linkFormSort, this.type, this.name, dataStr);
        GlobalTool.logInfo(format);
        excute(uid, flowType, linkType, data);
    }

    /**
     * 执行某流程、环节下该表单处理逻辑
     * <p>
     * 注意：一个表单可能参与多个流程或环节。需要区分代码逻辑。
     */
    public abstract void excute(String uid, String flowType, String linkType, Object data);
}
